package com.css.apps.base.user.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.css.apps.base.post.model.SPost;
import com.css.apps.base.user.model.SUser;
import com.css.core.configuration.Environment;
import com.css.db.page.Page;
import com.css.db.query.QueryCache;
import com.css.util.Ajax;
import com.css.util.Messages;
import com.css.webbase.webwork.action.AdminAction;
import com.opensymphony.xwork.Action;

@SuppressWarnings("serial")
public class DirUserPost extends AdminAction {
	private static Log log = LogFactory.getLog(DirUserRole.class);
	private Page page;
	private String orgId;
	private String userId;
	private List<SPost> PostList;

	public DirUserPost() {
		page = new Page();
		page.setCurrentPage(1);
		page.setPageSize(11);
		page.setCountField("a.uuid");
	}

	@SuppressWarnings("unchecked")
	@Override
	protected String adminGo() {
		try {
			SUser sUser = QueryCache.get(SUser.class, userId);
			if (sUser == null) {
				result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.failed"));
				return Action.ERROR;
			}
			List<String> userPostList = sUser.getPostList().getListById();// 用户目前分配的岗位列表
			PostList = QueryCache.idToObj(SPost.class, userPostList);
			return SUCCESS;
		} catch (Exception ex) {
			result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.exception"));
			log.error(ex.getMessage(), ex);
			return Action.ERROR;
		}
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public List<SPost> getPostList() {
		return PostList;
	}

	public void setPostList(List<SPost> postList) {
		PostList = postList;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public String getOrgId() {
		return orgId;
	}

	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}

}
